package com.qf.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.qf.Hall;
import com.qf.ResultVo;
import com.qf.Scenes;
import com.qf.mapper.HallMapper;
import com.qf.mapper.ScenesMapper;
import com.qf.service.ScenesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作者：Xx凯丶
 * 时间：2022/4/21 15:29
 */
@Service
public class ScenesServiceImpl implements ScenesService {
    @Autowired
    private ScenesMapper scenesMapper;
    @Autowired
    private HallMapper hallMapper;
    @Override
    public ResultVo searchScenesByMovieIdAndCinemaId(Integer movieId, Integer cinemaId) {
        LambdaQueryChainWrapper<Scenes> scenesLambdaQueryChainWrapper = new LambdaQueryChainWrapper<>(scenesMapper);
        List<Scenes> scenes = scenesLambdaQueryChainWrapper
                .eq(Scenes::getMovieId, movieId)
                .eq(Scenes::getCinemaId, cinemaId)
                .list();
        LambdaQueryChainWrapper<Hall> wrapper = new LambdaQueryChainWrapper<>(hallMapper);
        scenes.forEach(s->{
            Hall hall = wrapper.eq(Hall::getHallId, s.getHallId()).one();
            s.setHallName(hall.getHallName());
        });
        return new ResultVo(200,"SUCCESS",scenes);
    }
}
